export default class Button {
  constructor() {
    this.plugin = {
      name: "xiaoyao-cvs-plugin",
      dsc: "xiaoyao-cvs-plugin",
      priority: 100,
      rule: [
      {
        reg: "^#*((刷新|更新|获取|绑定)(ck|cookie))|((扫码|二维码|辅助)(登录|绑定|登陆))|((账号|密码)(密码)?(登录|绑定|登陆))|((图鉴|ck|cd|CD)帮助)$",
        fnc: "user",
      },
      {
        reg: `^#*(米游社|mys|社区)?(原神|星铁|崩坏3|崩坏2|未定事件簿|大别野|崩坏星穹铁道|绝区零|全部)?签到$`,
        fnc: "sign",
      },
      {
        reg: `^#*(原神|星铁|全部|全|多)?体力(帮助)?$`,
        fnc: "note",
      },
      {
        reg: `^#*(原神|星铁)?(((更新|获取|导出)?抽卡记录)|((全部)?(抽卡|抽奖|角色|武器|集录|常驻|up|新手|光锥|全部)池*(记录|祈愿|分析|统计))|((记录|抽卡|安卓|苹果|电脑|pc|ios)帮助))$`,
        fnc: "gacha",
      },
      {
        reg: 'authkey=',
        fnc: "gacha",
      },
      {
        reg: /\[uid\:\d+\]/,
        fnc: "gacha",
      },
      {
        reg: '(stoken|ct|login_ticket)=',
        fnc: "user",
      },
      {
        reg: '(ltoken|ltoken_v2).*(ltuid|login_uid|ltmid_v2)',
        fnc: "user",
      },
      ]
    }
  }

  async user(){
    const list = [
      { label: '签到', callback: `/签到` },
      { label: '体力', callback: `/体力` },
      { label: '深渊', callback: `/深渊` },

      { label: '社区签到', callback: `/米游社原神签到` },
      { label: '今日素材', callback: `/今日素材` },
      { label: '原石统计', callback: `/原石统计` },
      
      { label: '更新记录', callback: `/更新抽卡记录` },
      { label: '圣遗物列表', callback: `/圣遗物列表` },
      { label: '练度统计', callback: `/练度统计` },

      { label: `扫码绑定`, callback: `/扫码绑定` },
      { label: `刷新CK`, callback: `/刷新ck` },
      { label: `刷新CD`, callback: `/刷新CD` },
      { label: `获取小助手记录`, callback: `/获取小助手记录` },
    ]
    return Bot.Button(list)
  }

  async sign(){
    const list = [
      [
        { label: `签到`, callback: `/签到` },
        { label: `体力`, callback: `/体力` },
        { label: '社区', callback: `/米游社全部签到` },
      ],[
        { label: `扫码绑定`, callback: `/扫码绑定` },
        { label: `刷新CK`, callback: `/刷新ck` },
      ],[
        { label: '打赏' , link: 'https://afdian.net/a/ye3011'},
        { label: '反馈' , link: 'http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=dGwUMbO9IBj9TPGmGLmZ1HMBw5b6zaTK&authKey=e9KIcoWA2QVtQ2N0%2BBIzF3DzyR7JoSwSZkNPkXc4aI6nKzO%2Bl9KAmd%2FQ5ZXtMB4b&noverify=0&group_code=692425673'},
        { label: '拉群' , link: 'https://qun.qq.com/qunpro/robot/qunshare?robot_uin=3889005294&robot_appid=102082668&biz_type=0'},
      ]
    ]
    return Bot.Button(list)
  }

  async note(){
    const list = [
      [
        { label: `签到`, callback: `/签到` },
        { label: `体力`, callback: `/体力` },
        { label: '社区', callback: `/米游社全部签到` },
      ],[
        { label: `扫码绑定`, callback: `/扫码绑定` },
        { label: `刷新CK`, callback: `/刷新ck` },
      ],[
        { label: '打赏' , link: 'https://afdian.net/a/ye3011'},
        { label: '反馈' , link: 'http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=dGwUMbO9IBj9TPGmGLmZ1HMBw5b6zaTK&authKey=e9KIcoWA2QVtQ2N0%2BBIzF3DzyR7JoSwSZkNPkXc4aI6nKzO%2Bl9KAmd%2FQ5ZXtMB4b&noverify=0&group_code=692425673'},
        { label: '拉群' , link: 'https://qun.qq.com/qunpro/robot/qunshare?robot_uin=3889005294&robot_appid=102082668&biz_type=0'},
      ]
    ]
    return Bot.Button(list)
  }

  async gacha(e){
    const list = [
        { label: `角色记录`, callback: `/星铁角色记录` },
        { label: `光锥记录`, callback: `/星铁光锥记录` },
        { label: `全部记录`, callback: `/星铁全部记录` },

        { label: `角色统计`, callback: `/星铁角色统计` },
        { label: `光锥统计`, callback: `/星铁光锥统计` },
        { label: `全部统计`, callback: `/星铁全部统计` },
  ]
  return Bot.Button(list)
}  
async gacha(e){
  const game = e.isSr ? '星铁' : ''
   const list = [
      [
        { label: `角色记录`, callback: `/${game}角色记录` },
        { label: `武器记录`, callback: `/${game}${game ? '光锥' : '武器'}记录` },
        { label: `常驻记录`, callback: `/${game}常驻记录` },
      ],[
        { label: `角色统计`, callback: `/${game}角色统计` },
        { label: `武器统计`, callback: `/${game}${game ? '光锥' : '武器'}统计` },
        { label: `常驻统计`, callback: `/${game}常驻统计` },
      ],[
        { label: `全部记录`, callback: `/${game}全部记录` },
        { label: `全部统计`, callback: `/${game}全部统计` },
        { label: `集录记录`, callback: `/集录记录` },
      ],[
        { label: `扫码绑定`, callback: `/扫码绑定` },
        { label: `刷新CK`, callback: `/刷新ck` },
        { label: `刷新CD`, callback: `/刷新CD` },
      ],[
        { label: `更新记录`, callback: `/更新抽卡记录` },
        { label: `获取小助手记录`, callback: `/获取小助手记录` },
      ]
    ]
    return Bot.Button(list)
  }
}

function toButton(list, line = 3) {
  let button = []
  let arr = []
  let index = 1
  for (const i of list) {
    arr.push({
      id: String(Date.now()),
      render_data: {
        label: i.label,
        style: 1
      },
      action: {
        type: 2,
        permission: { type: 2 },
        data: i.data,
        unsupport_tips: "code: 45",
      }
    })
    if (index % line == 0 || index == list.length) {
      button.push({type: 'button',
        buttons: arr
      })
      arr = []
    }
    index++
  }
  return button
}
